//
//  YCTabBarController.m
//  美丽衣橱
//
//  Created by 方赫 on 16/4/18.
//  Copyright © 2016年 FH. All rights reserved.
//

#import "YCTabBarController.h"
#import "YCHomePageController.h"
#import "YCCategoryController.h"
#import "YCShopViewController.h"
#import "YCMineTableViewController.h"


@interface YCTabBarController ()

@end

@implementation YCTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 1. 添加所有子控制器
    [self setUpAllChildViewController];
}

- (void)setUpAllChildViewController {
    
    // 首页
    YCHomePageController *homePage = [[YCHomePageController alloc] init];
    homePage.view.backgroundColor = [UIColor blueColor];
    [self setChildViewContrller:homePage
                          title:@"首页"
                          image:[UIImage imageWithOriginRenderMode:@"yuike_maintab_home_nor"]
                  selectedImage:[UIImage imageWithOriginRenderMode:@"yuike_maintab_home_sel"]];
    
    // 分类
    YCCategoryController *category = [[YCCategoryController alloc] init];
    category.view.backgroundColor = [UIColor redColor];
    [self setChildViewContrller:category
                          title:@"分类"
                          image:[UIImage imageWithOriginRenderMode:@"yuike_maintab_category_nor"]
                  selectedImage:[UIImage imageWithOriginRenderMode:@"yuike_maintab_category_sel"]];
    
    // 购物车
    YCShopViewController *shop = [[YCShopViewController alloc] init];
    shop.view.backgroundColor = [UIColor orangeColor];
    [self setChildViewContrller:shop
                          title:@"购物车"
                          image:[UIImage imageWithOriginRenderMode:@"yuike_maintab_shopcart_nor"]
                  selectedImage:[UIImage imageWithOriginRenderMode:@"yuike_maintab_shopcart_sel"]];
    
    // 我的
    YCMineTableViewController *mine = [[YCMineTableViewController alloc] init];
    mine.view.backgroundColor = [UIColor grayColor];
    [self setChildViewContrller:mine
                          title:@"我的"
                          image:[UIImage imageWithOriginRenderMode:@"yuike_maintab_space_nor"]
                  selectedImage:[UIImage imageWithOriginRenderMode:@"yuike_maintab_space_sel"]];
}

- (void)setChildViewContrller:(UIViewController *)vc title:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectedImage {
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    
    vc.navigationItem.title = title;
    vc.tabBarItem.image = image;
    vc.tabBarItem.selectedImage = selectedImage;
    
    // 调整tabBarItem的位置
    vc.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
    
    if ([vc isKindOfClass:[YCHomePageController class]]) {
        [vc.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:255/255.0 green:71/255.0 blue:149/255.0 alpha:1]];
    }
    
    [self addChildViewController:nav];
}


@end
